package com.yb.core.exception;


import com.yb.core.enums.HttpCode;
import lombok.Data;

/**
 * 业务异常，主要用于全局异常handler处理
 * 注意，如果是服务间调用，则不能抛出此异常，会触发熔断
 * 想避免触发熔断，需要在FeignClient注解中配置Configuration
 */

/**
 * 已将RuntimeException改成HystrixBadRequestException
 * HystrixBadRequestException不会触发熔断
 * 适用于业务的异常，如参数缺失，数据重复等业务判断异常
 */

@Data
public class XczxBusinessException extends RuntimeException {

    private int code;

    private String message;

    public XczxBusinessException() {
        this("This is blank message");
    }

    public XczxBusinessException(Exception e) {
        super(e);
    }
    public XczxBusinessException(String msg) {
        this(HttpCode.Response.ERROR.getCode() , msg);
    }

    public XczxBusinessException(int code, String msg) {
        super(msg);
        this.code = code;
        this.message = msg;
    }

    public XczxBusinessException(HttpCode.Response response) {
        super(response.getMsg());
        this.code = response.getCode();
        this.message = response.getMsg();
    }

}
